define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'reservation/reservation/index' + location.search,
                    add_url: 'reservation/reservation/add',
                    edit_url: 'reservation/reservation/edit',
                    del_url: 'reservation/reservation/del',
                    multi_url: 'reservation/reservation/multi',
                    import_url: 'reservation/reservation/import',
                    table: 'reservation',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'user_id', title: __('User_id')},
                        // {field: 'shop_id', title: __('Shop_id')},
                        {field: 'res_no', title: __('Res_no'), operate: 'LIKE'},
                        
                        {field: 'user.nickname', title: __('预约人姓名'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('预约人电话'), operate: 'LIKE'},
                        // {field: 'order_id', title: __('Order_id')},
                        // {field: 'goods_id', title: __('Goods_id')},
                        // {field: 'sku_id', title: __('Sku_id')},
                        {field: 'title', title: __('预约内容'), operate: 'LIKE'},
                        {field: 'difference', title: __('Difference'), operate: 'LIKE'},
                        {field: 'quantity', title: __('Quantity')},

                       // {field: 'staff_id', title: __('Staff_id')},
                        {field: 'staff.name', title: __('预约人员'), operate: 'LIKE'},
                        {field: 'stime', title: __('预约时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'state', title: __('预约方式'), searchList: {"1":__('State 1'),"2":__('State 2')}, formatter: Table.api.formatter.normal},
                       // {field: 'remarks', title: __('Remarks'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                      
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5')}, formatter: Table.api.formatter.status},
                       // {field: 'etime', title: __('Etime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'staff.name', title: __('Staff.name'), operate: 'LIKE'},
                        // {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        // {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        // {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
